const Koa = require('koa');

const app = new Koa();

const bodyparser = require('koa-bodyparser');

const router = require('koa-router')();

const query = require('./db/query');

app.use(bodyparser())  //bodyparser一定要放在路由挂载之前

app.use(async (ctx,next) => {
    console.log("ctx第一个中间")
    console.log(ctx.query) // {key:'羽绒服'}
    console.log(ctx.querystring);  //key=xxx&type=xxx
    console.log(ctx.request.body);
    await next()
})

app.use(router.routes());

app.use(router.allowedMethods());  

// router.post('/api/login',ctx => {
//     console.log("/api/login",ctx.request.body);
//     ctx.body = ctx.request.body;
// })

// router.post('/api/registry',(ctx) => {
//     ctx.request.body
// })

const connecttion = require('./db/db');

router.get('/api/userlist',async (ctx,next) => {
    let data = await query('delete from userlist where id=4')
    ctx.body = data
})

app.listen(process.env.PORT || 3000,() => {
    console.log("服务启动成功")
})